<template>
  <div class="account-data">
    <!-- 数据列表 -->
    <el-table :data="tableData" border style="width:100%" v-loading="loading" element-loading-text="拼命加载中">
      <el-table-column label="客户手机号码">
        <template slot-scope="scope">
          <span>{{ scope.row.userTel }}</span>
        </template>
      </el-table-column>

      <el-table-column label="客户姓名">
        <template slot-scope="scope">
          <span>{{scope.row.userName}}</span>
        </template>
      </el-table-column>

      <el-table-column label="预约时间">
        <template slot-scope="scope">
          <span>{{ formatDate(scope.row.Oreservetime)}}</span>
        </template>
      </el-table-column>

      <el-table-column label="确定订单时间">
        <template slot-scope="scope">
          <span>{{ scope.row.Osuretime === '' ? scope.row.Osuretime:formatDate(scope.row.Osuretime) }}</span>
        </template>
      </el-table-column>

      <el-table-column label="摄影师姓名">
        <template slot-scope="scope">
          <span>{{scope.row.sheyinshiName}}</span>
        </template>
      </el-table-column>

      <el-table-column label="摄影师等级">
        <template slot-scope="scope">
          <span>{{ roleName(scope.row.sheyinshiDj) }}</span>
        </template>
      </el-table-column>

      <el-table-column label="摄影师手机号">
        <template slot-scope="scope">
          <span>{{ scope.row.sheyinshiTel}}</span>
        </template>
      </el-table-column>

      <el-table-column label="服装名称">
        <template slot-scope="scope">
          <span>{{scope.row.ClothingName}}</span>
        </template>
      </el-table-column>

      <el-table-column label="结算价格">
        <template slot-scope="scope">
          <span>{{scope.row.Omoney}}</span>
        </template>
      </el-table-column>

      <el-table-column label="订单编号">
        <template slot-scope="scope">
          <span>{{scope.row.Orderid}}</span>
        </template>
      </el-table-column>

      <el-table-column label="拍摄时间">
        <template slot-scope="scope">
          <span>{{scope.row.ShootingTime}}</span>
        </template>
      </el-table-column>

      <el-table-column label="拍摄地点">
        <template slot-scope="scope">
          <span>{{scope.row.FilmCity}}</span>
        </template>
      </el-table-column>

      <el-table-column label="订单状态">
        <template slot-scope="scope">
          <span>{{ orderState(scope.row.OrderState)}}</span>
        </template>
      </el-table-column>

      <el-table-column label="操作" width='180px'>
        <template slot-scope="scope">
          <el-button @click="handleDelete(scope.row)" size="mini" type="danger">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页 -->
    <div class="pages" ref="page-box">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        background
        layout="prev, pager, next"
        :page-size="pages"
        :total="total">
      </el-pagination>
    </div>
  </div>
</template>

<script lang="ts">
import { Component, Vue } from "vue-property-decorator";

@Component({
  components: {  }
})
export default class AccountData extends Vue {
  tableData: any = [];
  total:number = 0; // 总数据量
  pages:number = 5; // 每页数据量
  pageNumber: number = 0; // 页码
  loading:boolean = true;// loading加载
  dialogVisibleEdit: Boolean = false; // 编辑模态框显示状态
  Fuzhuangid:Number = 0; // 数据ID

  // 对象数据
  listObj: any = {
    Ftype:'', Fmoney:''
  };

  created() {
    this.getData();
  }

  // 隐藏新增账户
  closeDialog() {
    this.dialogVisibleEdit = false;
  }

  // 删除
  handleDelete(row: any): void {
    (this as any).$confirm('是否确认删除？')
    .then((res:any)=> {
      const { Oid } = row;

      (this as any).$axios.post('/order/del', { Oid }).then((res: any) => {
        if(res.data.code === 200){
            this.getData();
            (this as any).$message({
              message: res.data.data,
              type: "success"
            })
          }
          else{
            (this as any).$message.error(res.data.data)
          }
      })
    }) 
  }

  // 数据显示
  getData() {
    this.loading = true;
    const param = {
      pages: this.pages,
      pageNumber: this.pageNumber
    };

    (this as any).$axios("/order/dataList", { params:param }).then((res: any) => {
      this.loading = false;

      if(res.data.code === 200){
        this.tableData = res.data.data.list;
        this.total = res.data.data.sum;
      }
    })
  }

  // 分页 pageSize 改变时会触发
  handleSizeChange(val: number) {
    if(val === 1){
      this.pageNumber = 0
    }
    else{
      this.pageNumber = (val-1) * this.pages;
    }
    this.getData();
  }

  // 分页 currentPage 改变时会触发
  handleCurrentChange(val: number) {
    if(val === 1){
      this.pageNumber = 0
    }
    else{
      this.pageNumber = (val-1) * this.pages;
    }
    this.getData();
  }

  // 等级名称
  roleName(type:number){
    let str = ''

    switch(type){
      case 1: str = '初级'; break;
      case 2: str = '中级'; break;
      case 3: str = '高级'; break;
    }
    return str;
  }

  // 预约单完成状态
  orderState(type:number){
    let str = ''

    switch(type){
      case 1: str = '预约中'; break;
      case 2: str = '已完成'; break;
    }
    return str;
  }

    /**
   * @param {数值类型} date
   */
  formatDate(date:any){
      date = new Date(date*1);
      var y  =  date.getFullYear();
      var m  =  date.getMonth()+1;
      var d  =  date.getDate();
      var h  =  date.getHours();
      var m1  =  date.getMinutes();
      var s  =  date.getSeconds();
      m  =  m<10?("0"+m):m;
      d  =  d<10?("0"+d):d;
      return y+"-"+m+"-"+d+" "+h+":"+m1+":"+s;
  }
}
</script>

<style lang="scss" scoped>
.account-data {
  height: 100%;
  overflow: auto;
  .add-box {
    margin-bottom: 10px;
  }
}
.pages{
  width: 100%;
  margin-top: 10px;
  background: white;
  display: flex;
  justify-content: flex-end;
  padding: 20px 0;
}

.form-box {
  .el-input,
  .el-select {
    width: 400px !important;
  }
}
</style>
